home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / examples / euclid < prev    next >
Text File  |  1994-09-20  |  468b  |  27 lines

  1. //-------------------------------------------------------------------//
  2. //  Euclid's algorithm
  3. //
  4.  
  5. //  Syntax:    euclid ( M , N )
  6.  
  7. //  Description:
  8.  
  9. //  Euclid's algorithm computes the greatest common divisor of two
  10. //  integers (M, and N).
  11. //-------------------------------------------------------------------//
  12.  
  13. euclid = function ( M , N )
  14. {
  15.   local( M, N )
  16.  
  17.   r = 1;
  18.   while(r)
  19.   {
  20.     r = mod(M,N);
  21.     if(r == 0) { break; }
  22.     M = N;
  23.     N = r;
  24.   }
  25.   return N;
  26. };
  27.